/*  Copyright 2010 Daniel Brasil Magnani
 *  Created on: Dec 20, 2010
 *      Author: daniel
 */

#ifndef CSP_SOLUTION_H_
#define CSP_SOLUTION_H_

#include <algorithm>
#include <vector>
#include "chronometer.h"
#include "instance.h"

class Solution {
 public:
  // Get method for the solution.
  std::vector<Car> get_solution();
  // Initialize the solution
  explicit Solution(const std::vector<Car> &solution);
  // Execute the swap local search with first choice
  int VFLS(float time_limit, int algorithm = 0, int target = 0);
  int LocalSearch(int algorithm = 0, int improving = 1);
 private:
  std::vector<std::vector<int> > M1_;
  std::vector<std::vector<int> > M2_;
  std::vector<std::vector<int> > M3_;
  int *map_;
  std::vector<int*> max_profit_;
  std::vector<Car> solution_;
  int solution_size_;
  int constraint_size_;
  int yesterday_size_;

  // Update M1
  void CalculateSolution();
  void CreateStructures(int algorithm = 0);
  void UpdateStructures(int u, int v, int algorithm = 0);
  // Update M2 and M3
  void UpdateM_();
  void UpdateM1(int u);
  // Retrieve the variation of violations of the swap of the car in position
  // i for j, within the constraint k.
  int SwapVariation(int i, int j, int k, int algorithm = 0);
  // Retrieve the cost of the swap operation between cars i and j for the
  // constraint k
  int SwapCost(int i, int j, int k, int algorithm = 0);
  // Retrieve the cost of the insertion operations between cars i and j for the
  // constraint k
  void Swap(int i, int j);
  void GetCars(int* cars);
};

#endif  // CSP_SOLUTION_H_
